function settings = check_initial_setup(settings)
% check settings, set default values
settings.start_time = tic;

% if PRNG seeds for random subspaces and bootstrap samples not specified, generate them randomly
if ~isfield(settings,'seed_subspaces') || ~isfield(settings,'seed_bootstrap')
    rand('state',sum(100*clock));
    if ~isfield(settings,'seed_subspaces')
        settings.seed_subspaces = round(rand()*899999997+100000001);
    end
    if ~isfield(settings,'seed_bootstrap')
        settings.seed_bootstrap = round(rand()*899999997+100000001);
    end
end

% default location of a log-file
if ~isfield(settings,'output')
    settings.output = ['output/' date() '_1.log'];
    i = 1;
    while exist(settings.output,'file')
        i = i+1;
        settings.output = ['output/' date() '_' num2str(i) '.log'];
    end
end

% check cover,stego,seed_trntst
if ~isfield(settings,'cover'),  error('ERROR: settings.cover not specified.'); end
if ~isfield(settings,'stego'),  error('ERROR: settings.stego not specified.'); end
if ~ischar(settings.cover) && (length(settings.cover)~=length(settings.stego)),error('ERROR: settings.cover and settings.stego do not have equal lengths.');end
if ~isfield(settings,'seed_trntst'),   error('ERROR: settings.seed not specified.');  end

% set default values
if ~isfield(settings,'ratio'), settings.ratio = 0.5; end
if ~isfield(settings,'L'),     settings.L = 'automatic'; end
if ~isfield(settings,'d_sub'), settings.d_sub = 'automatic'; end
settings.k = settings.d_sub;
if ~isfield(settings,'bootstrap'), settings.bootstrap = 1; end
if ~isfield(settings,'normalize'), settings.normalize = 0; end
if ~isfield(settings,'type'), settings.type = 'FLD'; end
if ~isfield(settings,'criterion'), settings.criterion = 'min(MD+FA)'; end
if ~isfield(settings,'fusion_strategy'), settings.fusion_strategy = 'majority_voting'; end
if ~isfield(settings,'verbose'), settings.verbose = 1; end
if ~isfield(settings,'keep_cov'), settings.keep_cov = 'no'; end
if settings.keep_cov == 0, settings.keep_cov = 'no'; end
if settings.keep_cov == 1, settings.keep_cov = 'memory'; end

if ~isfield(settings,'max_number_base_learners')
    settings.max_number_base_learners = 500;
end


if ~isfield(settings,'ignore_warnings')
    % ignore 'MATLAB:nearlySingularMatrix' warning during FLD => speed-up
    % (no effect on performance according to our experiments)
    settings.ignore_warnings = true;
end

% Set default values for the automatic stopping criterion for L
if ischar(settings.L)
    if ~isfield(settings,'L_kernel'),     settings.L_kernel = ones(1,5)/5; end
    if ~isfield(settings,'L_min_length'), settings.L_min_length = 25; end
    if ~isfield(settings,'L_memory'),     settings.L_memory = 50; end
    if ~isfield(settings,'L_epsilon'),    settings.L_epsilon = 0.005; end
    settings.bootstrap = 1;
end

% Set default values for the search for the subspace dimension k
if ischar(settings.k)
    if ~isfield(settings,'Eoob_tolerance'), settings.Eoob_tolerance = 0.02; end
    if ~isfield(settings,'k_step'), settings.k_step = 200; end
    settings.bootstrap = 1;
    settings.improved_search_for_k = 1;
else
    settings.improved_search_for_k = 0;
end

initial_screen_output(settings);
